import { createRouter, createWebHistory } from 'vue-router'
import Layout from '@/layout'
// import { useBasicData } from '@/store'

export const menus = [
  {
    path: '/custom',
    component: Layout,
    name: 'custom',
    redirect: '/customPage',
    children: [
      {
        path: '/customPage',
        name: 'customPage',
        redirect: '/customPage/goods',
        meta: {
          title: '顾客'
        },
        children: [
          {
            path: '/customPage/goods',
            name: 'customPage-goods',
            component: () => import('@/views/custom/Goods.vue'),
            meta: {
              title: '商品'
            }
          },
          {
            path: '/customPage/order',
            name: 'customPage-order',
            component: () => import('@/views/custom/Order.vue'),
            meta: {
              title: '订单'
            }
          },
          {
            path: '/customPage/address',
            name: 'customPage-address',
            component: () => import('@/views/custom/Address.vue'),
            meta: {
              title: '地址管理'
            }
          }
        ]
      }
    ]
  },
  {
    path: '/manage',
    component: Layout,
    name: 'manage',
    redirect: '/managePage',
    children: [
      {
        path: '/managePage',
        name: 'managePage',
        redirect: '/manage/user',
        meta: {
          title: '管理员'
        },
        children: [
          {
            path: '/manage/user',
            name: 'manage-user',
            component: () => import('@/views/manage/User.vue'),
            meta: {
              title: '用户管理'
            }
          },
          {
            path: '/manage/shop',
            name: 'manage-shop',
            component: () => import('@/views/manage/Shop.vue'),
            meta: {
              title: '店铺管理'
            }
          },
          {
            path: '/manage/goods',
            name: 'manage-goods',
            component: () => import('@/views/manage/Goods.vue'),
            meta: {
              title: '商品管理'
            }
          },
          {
            path: '/manage/order',
            name: 'manage-order',
            component: () => import('@/views/manage/Order.vue'),
            meta: {
              title: '订单管理'
            }
          }
        ]
      }
    ]
  }
]

export const routes = [
  { path: '/', redirect: '/login', hidden: true },
  { path: '/login', component: () => import('@/views/login/Login.vue'), hidden: true },
  ...menus
]
const BATH_PATH = import.meta.env.VITE_BASE_PATH
export const router = createRouter({
  history: createWebHistory(BATH_PATH),
  routes
})

// 路由守卫

// router.beforeEach(async () => {
//   const basicData = useBasicData()
//   await basicData.getDeviceList()
// })
